﻿package mortal.game.view.guild.otherpanel
{
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.guild.cellrender.*;
    import mortal.game.view.guild.util.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildResourceAllotPanel extends SmallWindow
    {
        private var _sortUpBtn:GLoadedButton;
        private var _list:GTileList;
        private var _confirmBtn:GButton;
        private var _pageSelecter:PageSelecter;
        private var _pageTool:PageTool;
        private static var _instance:GuildResourceAllotPanel;

        public function GuildResourceAllotPanel(param1:ILayer = null)
        {
            this._pageTool = new PageTool([], 5);
            super(param1);
            setSize(520, 395);
            title = Language.getString(70536);
            return;
        }// end function

        private function onConfirmBtnClick(event:MouseEvent) : void
        {
            var _loc_5:Array = null;
            var _loc_6:String = null;
            var _loc_2:* = GuildResourceRecordUitl.instance.notEnoughMap;
            if (_loc_2)
            {
                _loc_5 = [];
                for (_loc_6 in _loc_2)
                {
                    
                    _loc_5.push(int(_loc_6));
                }
                GuildResourceAllotTipPanel.instance.show();
                GuildResourceAllotTipPanel.instance.data = _loc_5;
                return;
            }
            var _loc_3:* = GuildResourceRecordUitl.instance.allPlayerItem;
            if (_loc_3.length <= 0)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71223));
                return;
            }
            var _loc_4:Object = {};
            _loc_4.oper = new EGuildWarehouseOper(EGuildWarehouseOper._EGuildWarehouseAllocation);
            _loc_4.item = _loc_3;
            _loc_4.oprMoney = null;
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_oper, _loc_4));
            return;
        }// end function

        private function onSelectItemUpdata(event:DataEvent) : void
        {
            this.onListPageChange();
            return;
        }// end function

        private function onSortUpBtnClick(event:MouseEvent = null) : void
        {
            this._pageTool.array.sortOn("contributionWeek", Array.NUMERIC | Array.DESCENDING);
            this.onListPageChange();
            return;
        }// end function

        private function onInfoRes(param1:Object) : void
        {
            this._pageTool.array = param1 as Array;
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this.onSortUpBtnClick();
            return;
        }// end function

        private function onallocationSuccess(param1:Object) : void
        {
            GuildResourceRecordUitl.instance.clean();
            this.onListPageChange();
            return;
        }// end function

        private function onListPageChange(event:Event = null) : void
        {
            this._list.dataProvider = new DataProvider(this._pageTool.getByPageNo(this._pageSelecter.currentPage));
            this._list.drawNow();
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            if (GuildResourceAllotTipPanel.isShow)
            {
                GuildResourceAllotTipPanel.instance.hide();
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(9, 34, 517, 30, this, ImagesConst.RegionTitleBg));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(70529), 14, 40, 140, 20, this, GlobalStyle.textFormatHuang.center()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(70530), 154, 40, 55, 20, this, GlobalStyle.textFormatHuang.center()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(70531), 209, 40, 120, 20, this, GlobalStyle.textFormatHuang.center()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(70532), 329, 40, 190, 20, this, GlobalStyle.textFormatHuang.center()));
            this._sortUpBtn = UIFactory.gLoadedButton(ImagesConst.ascendingSortBtn_upSkin, 208, 44, 11, 14, this);
            this._list = UIFactory.tileList(13, 65, 500, 445, this);
            this._list.setStyle("cellRenderer", GuildResourceAllotRenderer);
            this._list.columnWidth = 397;
            this._list.rowHeight = 58;
            this._confirmBtn = UIFactory.gButton(Language.getString(70521), 440, 363, 62, 24, this);
            this._pageSelecter = UIFactory.pageSelecter(200, 365, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, new GTextFormat());
            this._pageSelecter.pageTextBoxSize = 40;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onListPageChange);
            this._confirmBtn.configEventListener(MouseEvent.CLICK, this.onConfirmBtnClick);
            this._sortUpBtn.configEventListener(MouseEvent.CLICK, this.onSortUpBtnClick);
            Dispatcher.addEventListener(EventName.GuildResourceSelectItemUpdata, this.onSelectItemUpdata);
            NetDispatcher.addCmdListener(ServerCommand.GuildParticipationInfoRes, this.onInfoRes);
            NetDispatcher.addCmdListener(ServerCommand.GuildWarehouseAllocationSuccess, this.onallocationSuccess);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            Dispatcher.removeEventListener(EventName.GuildResourceSelectItemUpdata, this.onSelectItemUpdata);
            NetDispatcher.removeCmdListener(ServerCommand.GuildParticipationInfoRes, this.onInfoRes);
            NetDispatcher.removeCmdListener(ServerCommand.GuildWarehouseAllocationSuccess, this.onallocationSuccess);
            this._sortUpBtn.dispose(param1);
            this._list.dispose(param1);
            this._confirmBtn.dispose(param1);
            this._pageSelecter.dispose(param1);
            GuildResourceRecordUitl.instance.clean();
            this._sortUpBtn = null;
            this._list = null;
            this._confirmBtn = null;
            this._pageSelecter = null;
            return;
        }// end function

        public static function get instance() : GuildResourceAllotPanel
        {
            if (_instance == null)
            {
                _instance = new GuildResourceAllotPanel;
            }
            return _instance;
        }// end function

        public static function get isShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
